//
//	(c) 2009 Andrew Kalmacky
//

#ifndef _AK_CHARS_H_
#define _AK_CHARS_H_

#include <string.h>
#include <stdio.h>
#include <cstdarg>

#ifdef T_
#undef T_
#endif

#ifdef MSVC
#pragma warning (disable: 4100)
#endif

#ifdef UNICODE

typedef wchar_t char_t;
#define T_(STR) L##STR
#define INTERNAL_STR(STR) L###STR

inline size_t strlen(const char_t* s) { return wcslen(s); }
inline int strcmp(const char_t* a, const char_t* b) { return wcscmp(a, b); }

#ifdef MSVC
inline void strcpy(char_t* dst, const char_t* src) { wcscpy_s(dst, ~0u, src); }
#else
inline void strcpy(char_t* dst, const char_t* src) { wcscpy(dst, src); }

#endif

#else

typedef char char_t;
#define T_(STR) STR
#define INTERNAL_STR(STR) #STR

#endif

#define STR(S) INTERNAL_STR(S)

inline void sprintf(char_t* buf, size_t buf_size, const char_t* format, ...)
{
	va_list l;
	va_start(l, format);
#ifdef UNICODE
#ifdef MSVC
	vswprintf(buf, buf_size, format, l);
#else
	vswprintf(buf, format, l);
#endif
#else
	vsnprintf(buf, buf_size, format, l);
#endif
	va_end(l);
}

#if defined(UNICODE) && defined(MSVC)
#define sscanf swscanf_s
#else
inline bool sscanf(const char_t* buf, const char_t* format, ...)
{
	va_list l;
	va_start(l, format);
#ifdef UNICODE
	bool r = vswscanf(buf, format, l);
#else
	bool r = vsscanf(buf, format, l);
#endif
	va_end(l);
	return r;
}
#endif

#endif // _AK_CHARS_H_
